<%
	/*@ 扩展对象静态方法 */
	Object.extend
	(
	 	String, 
		{
			interpret:function($value) 
			{
				return $value==null ? '':String($value);
			},
			specialChar:
			{
				'\b':'\\b',
				'\t':'\\t',
				'\n':'\\n',
				'\f':'\\f',
				'\r':'\\r',
				'\\':'\\\\'
			}
		}
	);
	/*@ 扩展对象的原型方法 */	
	Object.extend
	(
	 	String.prototype,
		{
			//->将英文字符串首字母大写
			capitalize:function()
			{
				return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase();
			},
			//->反编统一资源标识符
			decodeURI:function()
			{
				return decodeURI(this);
			},
			decodeURIComponent:function()
			{
				return decodeURIComponent(this);
			},
			decodeURL:function()
			{
				return decodeURI(this);
			},			
			//->反编HTML代码
			decodeHTML:function() 
			{
				return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
			},	
			//->编码HTML代码
			encodeHTML:function()
			{
				return Server.HTMLEncode(this);
			},				
			//->编码统一资源标识符
			encodeURI:function()
			{
				return encodeURI(this);
			},	
			encodeURIComponent:function()
			{
				return encodeURIComponent(this);
			},				
			encodeURL:function()
			{
				return encodeURI(this);
			},	
			//->是否以指定子字符串结尾
			endsWith:function($pattern) 
			{
				var d=this.length-$pattern.length;
				return d>=0&&this.lastIndexOf($pattern)===d;
			},			
			//->编码字符串
			escape:function()
			{
				return escape(this);
			},
			//->编码HTML
			escapeHTML:function()
			{
				return Server.HTMLEncode(this);
			},
			//->?解析JSON字符串
			evalJSON:function($sanitize) 
			{
				var json=this.unfilterJSON();
				try 
				{
					if(!$sanitize||json.isJSON()) return eval('(' + json + ')');
				} 
				catch(e) 
				{}
				throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
			},		
			//->
			evalScripts:function() 
			{
				return this.extractScripts().map
				(
				 	function(script) 
					{ 
						return eval(script); 
					}
				);
			},	
			//->筛选出脚本内容
			extractScripts:function() 
			{
				var matchAll=new RegExp(cusScriptFragment,'img');
				var matchOne=new RegExp(cusScriptFragment,'im');
				return (this.match(matchAll)||[]).map
				(
				 	function(scriptTag) 
					{
						return (scriptTag.match(matchOne)||['',''])[1];
					}
				);
			},			
			//->匹配处理字符串,返回处理结果
			gsub:function($pattern,$replacement) 
			{
				var result='',source=this,match;
				$replacement=arguments.callee.prepareReplacement($replacement);	
				while(source.length>0) 
				{
					if(match=source.match($pattern)) 
					{								
						result+=source.slice(0,match.index);
						result+=String.interpret($replacement(match));
						source=source.slice(match.index+match[0].length);
					} 
					else{
						result+=source,source='';
					}
				}
				return result;
			},		
			//编码HTML代码
			htmlEncode:function()
			{
				return Server.HTMLEncode(this);
			},
			//->是否包含子字符串
			inclue:function($string)
			{
				return this.indexOf($string)>-1;
			},
			//->解析字符串
			inspect:function($useDoubleQuotes) 
			{
				var escapedString=this.gsub
				(
				 	/[\x00-\x1f\\]/, 
					function(match) 
					{
						var character=String.specialChar[match[0]];
						return character ? character:'\\u00' + match[0].charCodeAt().toPaddedString(2,16);
					}
				);
				if($useDoubleQuotes) return '"'+escapedString.replace(/"/g,'\\"')+'"';
				return "'"+escapedString.replace(/'/g,'\\\'')+"'";
			},	
			//->按JSON解析字符串
			interpolate:function($object,$pattern) 
			{
				return new Template(this,$pattern).evaluate($object);
			},	
			//->检测是否是JSON字符串
			isJSON:function() 
			{
				var str=this.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"/g,'');
				return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
			},	
			//->将URL参数字符串解析成JSON对象
			parseQuery:function()
			{
				return this.toQueryParams();
			},
			//->检测字符串是不是空白字符
			isBlank:function()
			{
				return /^\s*$/.test(this);
			},
			//->检测是否是空字符
			isEmpty:function()
			{
				return this=='';
			},
			//->检测数字符串
			isNumeric:function($type)
			{
				return isNumeric($type);
			},
			//->检测是否以某个字符开头
			startsWith:function($pattern) 
			{
				return this.indexOf($pattern)===0;
			},			
			//->匹配处理字符串,返回处理结果.特殊的就是它能指定是否只返回第一个匹配
			sub:function($pattern,$replacement,$count) 
			{
				$replacement=this.gsub.prepareReplacement($replacement);
				$count=($count===undefined ? 1:$count);				
				return this.gsub
				(
				 	$pattern,
					function($match)
					{
						if(--$count<0) return $match[0];
						return $replacement($match);
					}
				);
			},
			//->处理每一个匹配结果返回字符串本身
			scan:function($pattern,$iterator) 
			{
				this.gsub($pattern,$iterator);
				return String(this);
			},	
			//->去除空格
			strip:function() 
			{
				return this.replace(/^\s+/,'').replace(/\s+$/,'');
			},
			//->去除标签
			stripTags:function() 
			{
				return this.replace(/<\/?[^>]+>/gi,'');
			},
			//->去除脚本
			stripScripts:function() 
			{
				return this.replace(new RegExp(cusScriptFragment,'img'),'');
			},	
			//->自增
			succ:function() 
			{
				return this.slice(0,this.length-1)+String.fromCharCode(this.charCodeAt(this.length-1)+1);
			},			
			//->重复字符
			times:function($count) 
			{
				return $count<1||isNaN($count) ? '':new Array($count+1).join(this);
			},			
			//->转换成数组
			doArray:function($separator,$limit)
			{
				return this.split(($separator||','),$limit);
			},
			//->转化成JSON字符串
			toJSON:function() 
			{
				return this.inspect(true);
			},	
			//->转换成数组
			toArray:function($separator,$limit)
			{
				return this.split(($separator||','),$limit);
			},
			//->字节转换
			toBytes:function()
			{
				var ret=[];
				for(var i=0;i<this.length;i++)
				{
					var u=this.charCodeAt(i);
					ret.push(u >> 8);			//右移8位获得高字节
					ret.push(u & 0xFF);			//逻辑与0xFF获得低字节
				}
				return ret;
			},	
			//->?把类URL参数的字符串解析成JSON字符串
			toQueryParams:function($separator) 
			{
				var match=this.strip().match(/([^?#]*)(#.*)?$/);
				if(!match) return {};
				
				return match[1].split($separator||'&').inject
				(
					{},
					function($hash,$pair)
					{							
						if(($pair=$pair.split('='))[0]) 
						{							
							var key=decodeURIComponent($pair.shift());
							var value=$pair.length>1 ? $pair.join('='):$pair[0];
							if(value!=undefined) value=decodeURIComponent(value);
							
							if(key in $hash) 
							{								
								if(!Object.isArray($hash[key])) $hash[key]=[$hash[key]];
								$hash[key].push(value);
							}
							else 
								$hash[key] = value;
						}
						return $hash;
					}
				);
			},			
			//->去除空白字符
			trim:function() 
			{
				return this.strip();
			},
			//->截取字符串
			truncate:function($length,$truncation) 
			{
				$length=$length||30;
				$truncation=(($truncation===undefined) ? '...':$truncation);
				return (this.length>$length) ? this.slice(0,$length-$truncation.length)+$truncation:String(this);
			},	
			//->匹配出JSON字符串
			unfilterJSON:function($filter)
			{
				return this.sub($filter||cusJSONFilter,'#{1}');
			},
			//->解码字符串
			unescape:function()
			{
				return unescape(this);
			},
			//->反编HTML
			unescapeHTML:function() 
			{
				return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
			},
			//->编码统一资源标识符
			urlEncode:function()
			{
				return Server.URLEncode(this);
			}
		}
	);	
	/*@ 扩展对象的辅助方法 */
	//->gsub辅助方法
	String.prototype.gsub.prepareReplacement=function($replacement) 
	{
		if(Object.isFunction($replacement)) return $replacement;
		var template=new Template($replacement);
		return function(match){return template.evaluate(match)};
	};	
%>